/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package game.platformer.levels;
import game.platformer.Player;
import game.platformer.platformer;
import org.anddev.andengine.engine.handler.IUpdateHandler;
import org.anddev.andengine.entity.primitive.Rectangle;

/*
 * 
 */

public class levelDeathBox extends Rectangle {
	//varBlock-----------------
	int lastEntryX;
	int lastEntryY;
	//-------------------------
	/**
	 *
	 * Any time a player leaes the box, he is
	 * sent to the last point used to enter the
	 * level
	 *
	 * @param xSize
	 * @param ySize
	 */
	public levelDeathBox(int xSize, int ySize){
		super(0, 0, xSize, ySize);
		setColor(0, 0, 0, 0);
		this.registerUpdateHandler(new IUpdateHandler() {
			public void onUpdate(float pSecondsElapsed){
				if(!collidesWith(Player.getPlayer().getSprite())){
					Player.getPlayer().hurt(1);
					Player.getPlayer().place(lastEntryX, lastEntryY);
				}
			}
			public void reset(){
				//do nothing
			}
		});
	}
	/**
	 * sets the point to reset the player to on death
	 * @param x x position
	 * @param y y position
	 */
	public void setLastEntryPoint(int x, int y){
		lastEntryX = x;
		lastEntryY = y;
	}

	public void place(){
		platformer.getScreenManager().getMapScreen().attachChild(this);
	}

	public void remove(){
		platformer.getScreenManager().getMapScreen().detachChild(this);
	}
}
